import 'package:flutter/material.dart';
import 'package:test1/View/MyRowText.dart';
import 'package:path_provider/path_provider.dart';

class Flutter_Data_Path_Provider_Page extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return Flutter_Data_Path_Provider_State();
  }
}

class Flutter_Data_Path_Provider_State
    extends State<Flutter_Data_Path_Provider_Page> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("path_provider"),
        ),
        body: ListView(
          children: <Widget>[
            MyRowText("获取sd卡的根路径", ()async{
              String sDCardDir = (await getExternalStorageDirectory()).path;
              debugPrint(sDCardDir);
            }),
            MyRowText("获取临时目录的路径", ()async{
              String sTempDir = (await getTemporaryDirectory()).path;
              debugPrint(sTempDir);
            }),
            MyRowText("获取文档目录的路径", ()async{
              String sDocumentDir = (await getApplicationDocumentsDirectory()).path;
              debugPrint(sDocumentDir);
            }),
          ],
        ),
      ),
    );
  }

}

/**
 * 1.在pubspec.yaml文件中声明依赖 PathProvider 插件
 *   dependencies:
 *   path_provider: ^0.5.0+1
 * 2.在pubspec.yaml顶部的动作功能区中点击“Packages Get”
 *
 * getExternalStorageDirectory,在iOS上，抛出异常，在Android上，这是getExternalStorageDirectory的返回值
 * getTemporaryDirectory,在iOS上，对应NSTemporaryDirectory（）返回的值，在Android上，这是getCacheDir的返回值。
 * getApplicationDocumentsDirectory,在iOS上，这对应NSDocumentsDirectory，在Android上，这是AppData目录
 */